package ia;

import book.Book;
import book.Booklist;
import org.w3c.dom.ls.LSOutput;

import java.util.Scanner;

public class Addbook implements IA{
    public void work(Booklist booklist){
        System.out.println("新增图书.........");

        int cutsize= booklist.getUsesize();
        if(cutsize == booklist.getBookslength()){
            System.out.println("书架满了，无法加入新书");
            return;
        }

            Scanner sc = new Scanner(System.in);
            System.out.println("请输入书名：");
            String bookname = sc.nextLine();
            System.out.println("请输入作者：");
            String author = sc.nextLine();
            System.out.println("请输入价格：");
            int isbn = sc.nextInt();
            sc.nextLine();
            System.out.println("请输入类型：");
            String publisher = sc.nextLine();

            Book book = new Book(bookname, author, isbn, publisher);
            //判断书架是否有这本书
            for(int i=0;i<booklist.getUsesize();i++){
                if (booklist.getBooks(i).equals(book)){
                    System.out.println("这本书已经存在，无法被加入");
                    return;
                }
            }
            booklist.setBooks(cutsize,book);
            booklist.setUsesize(cutsize+1);
            System.out.println("添加图书成功");

    }

}
